{layout name="common/layout" /}
<section class="panel">
    <header class="panel-heading">
        添加供货商
    </header>
    <div class="panel-body">
        <form class="form-horizontal" id="member_form">
            <div class="form-group">
                <label  class="col-lg-2 col-sm-2 control-label">供货商昵称</label>
                <div class="col-lg-10">
                    <input type="text" name="supplier_name" class="form-control" value="" >
                    <p class="help-block">如:拼图云商城</p>
                </div>
            </div>
            <div class="form-group">
                <label  class="col-lg-2 col-sm-2 control-label">用户帐号(手机号)</label>
                <div class="col-lg-10">
                    <input type="tel" name="supplier_mobile" class="form-control" value="" >
                    <p class="help-block">如:185***1235</p>
                </div>
            </div>
            <div class="form-group">
                <label  class="col-lg-2 col-sm-2 control-label">密码</label>
                <div class="col-lg-10">
                    <input type="password" name="supplier_pass" class="form-control" value="" >
                    <p class="help-block">如:a123456</p>
                </div>
            </div>
            <div class="form-group">
                <label  class="col-lg-2 col-sm-2 control-label">重复密码</label>
                <div class="col-lg-10">
                    <input type="password" name="repeat_pass" class="form-control" value="" >
                    <p class="help-block">如:a123456</p>
                </div>
            </div>
            <div class="form-group">
                <label  class="col-lg-2 col-sm-2 control-label">供货商头像</label>
                {:tplSingleImage('headimg')}
                <div class="row"></div>
                <div class="col-lg-5 col-lg-offset-2">建议尺寸(70*70)</div>
            </div>
            <div class="form-group">
                <label  class="col-lg-2 col-sm-2 control-label">是否允许直接发布商品</label>
                <div class="col-lg-5">
                    <input type="radio" name="is_build" value="1" checked>是
                    <input type="radio" name="is_build" value="0" >否
                    <p class="help-block">若允许则供货商发布的商品将不通过审核，否则则需审核上架</p>
                </div>
            </div>
            <div class="form-group">
                <div class="col-lg-offset-2 col-lg-10">
                    <button type="submit" class="btn btn-primary">保存</button>
                </div>
            </div>
        </form>
    </div>

</section>
<script type="text/javascript">
    $('#member_form').submit(function () {
        var member_name = $('input[name="supplier_name"]').val();
        if(!member_name){
            toastTop('用户昵称不能为空',2);
            return false;
        }
        var headimg = $('input[name="headimg"]').val();
        if(!headimg){
            toastTop('用户头像不能为空',2);
            return false;
        }
        var tel = $('input[name="supplier_mobile"]').val();
        if(!isPhone(tel)){
            toastTop('手机格式不正确',2);
            return false;
        }
        var pass = $('input[name="supplier_pass"]').val();
        if(!pass){
            toastTop('密码不能为空',2);
            return false;
        }else{
            var repeat_pass = $('input[name="repeat_pass"]').val();
            if(repeat_pass!=pass){
                toastTop('两次密码不一致',2);
                return false;
            }
        }

        $.ajax({
                    cache: true,
                    type: "POST",
                    url:'{:WebUrl('adminsupplier/add')}',
                    data:$('#member_form').serialize(),// 你的formid
                    async: false,
                    error: function(data) {
                        toastTop('服务器错误，稍后再试',2);
                    },
                    success: function(data) {
                        if(data.status=1){
                            toastTop('添加成功');
                            setTimeout(function(){
                                window.location='{:WebUrl('adminsupplier/index')}';
                            },600)
                        }else{
                            toastTop(data.info,2);
                        }
                    }
        },'json');
        return false;
    });


</script>
